import Vue from "vue";
import VueRouter from "vue-router";
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
//引入一级路由
import Index from "../pages/index.vue";
import Detail from "../pages/detail.vue";
import Order from "../pages/order.vue";
import Login from '../pages/login.vue'
Vue.use(VueRouter);

const routes = [
  {
    path: "/index",
    component: Index,
    children: [
      {
        path: "/home",
        component: ()=>import("../views/home"),
        name:'首页'
      },
      {
        path: "/sort",
        component: ()=>import("../views/sort"),
        name:'分类',
        alias:['/a','/b','/c'] //别名
      },
      {
        path: "/mine",
        component: ()=>import('../views/mine.vue'),
        meta:{ 
          name:'个人中心'
        }
      },
      {
        path: "/cart",
        component: ()=>import("../views/cart"),
       name:'购物车'
      },
      {
        //二级路由重定向
        path: "",
        redirect: "/home",
      },
    ],
  },
  {//动态路由
    path: "/detail",
    component: Detail,
    name:'商品详情'
  },
  {
    path: "/order",
    component: Order,
  },
  {
    path: "/login",
    component: Login,
    name:'登录'
  },
  {
    path:'/list',
    component:()=>import('../pages/list.vue'),
    name:'商品列表'
  },
  {
    path:'/register',
    component:()=>import('../pages/register.vue'),
    name:'注册'
  },
  {
    path: "*",
    redirect: "/index",
  },
];

const router = new VueRouter({
  mode:"hash",
  routes,
});

console.log(router,'路由的配置对象');

export default router;
